import VueRouter from 'vue-router'

// 导入登录和注册对应的路由组件
import Login from './components/Login/login.vue'
import register from './components/Login/register.vue'
import index from './components/Index/Index.vue'
import goods from './components/Goods/Goods.vue'
import single from './components/Single/Single.vue'
import address from './components/Address/Address.vue'
import deliver from './components/Deliver/Deliver.vue'
import message from './components/Deliver/Message.vue'


const router = new VueRouter({ // 创建路由对象
  mode: 'history', // 使用history模式
  linkActiveClass: 'my-active', // router-link-active
  linkExactActiveClass: 'my-exact-active',	// router-link-exact-active
  routes: [ // 配置路由规则
    { path: '/', redirect: '/index' },
    { path: '/login', component: Login, meta: { title: '登录' }},
    { path: '/register', component: register, meta: { title: '注册' }},
    { path: '/index',component:index},
    { path: '/goods',component:goods},
    { path: '/single',component:single},
    { path: '/address',component:address},
    { path: '/deliver',component:deliver},
    { path: '/message',component:message},
    
  ]
})

router.beforeEach((to, from, next) => {
  // 路由发生改变修改页面title
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
